//-------------------------------------------------------------------------------
//	file demo.cpp
//	brief
//		AudioCD demo
//
//	$Id: $
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//	Copyright and Disclaimer Notice
//
//	Copyright (c) 2013-2014 A.C. Verbeck
//	original author: Michel Helms (MichelHelms@Web.de).
//
//	This file is part of AudioCD: Audio CD reader
//
//	AudioCD is free software: you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation, either version 3 of the License, or
//	(at your option) any later version.
//
//	AudioCD is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with AudioCD.  If not, see <http://www.gnu.org/licenses/>.
//
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//	Environment
//	Make sure the files: "CBuf.h" & "AudioCD_Helpers.h"
//	are in the same directory as "CAudioCD.h"
//
//	Also, the files: "AudioCD_Helpers.cpp" and "CAudioCD.cpp"
//	are required for this project.
//------------------------------------------------------------------------------
#include <stdio.h>
#include "stdint.h"
#include "debug.h"

#include "CAudioCD.h"

#define CDROM_DRIVE 'D'

//------------------------------------------------------------------------------
//	Demo application
//------------------------------------------------------------------------------
int main(...)
{
	CAudioCD AudioCD;

	setvbuf(stdout, NULL, _IONBF, 0);
	setvbuf(stderr, NULL, _IONBF, 0);

//------------------------------------------------------------------------------
//	Open drive file-system
//------------------------------------------------------------------------------
	if (AudioCD.Open(CDROM_DRIVE) == false) {
		printf("Cannot open cd-drive: %c:!\n",CDROM_DRIVE);
		return 1;
	} else {
		printf("CD-drive: %c: opened.\n",CDROM_DRIVE);
	}

//------------------------------------------------------------------------------
//	Get / Print the Track Count
//------------------------------------------------------------------------------
	ULONG TrackCount = AudioCD.GetTrackCount();
	printf("Track-Count: %lu\n", TrackCount);

//------------------------------------------------------------------------------
//	Get / Print Track time for each track
//------------------------------------------------------------------------------
	for (ULONG i=0; i<TrackCount; i++) {
		ULONG Time = AudioCD.GetTrackTime(i);
		double tr_sz = (double)AudioCD.GetTrackSize(i)/1048576.0;
		printf("Track %02lu: %lu:%.2lu: %.2fmb\n", i+1, Time/60, Time%60, tr_sz);
	}

//------------------------------------------------------------------------------
//	Save a random track (number 7 in this case) to a file
//------------------------------------------------------------------------------
	printf("Extracting track 7...");
	if (AudioCD.ExtractTrack(7, "t7.wav") == false) {
		printf("Cannot extract track 7!\n");
		ErrorExit("AudioCD.ExtractTrack");
		return 1;
	} else {
		printf("done\n");
	}

//------------------------------------------------------------------------------
//	Move a track into RAM
//------------------------------------------------------------------------------
	CBuf<char> Buf;
	printf("Reading track 5...");
	if (AudioCD.ReadTrack(5, &Buf) == false) {
		printf("Cannot read track!\n");
		ErrorExit("AudioCD.ReadTrack");
		return 1;
	} else {
		printf("done\n");
	}

	return 0;
}

//
//	End: demo.cpp
//
